{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "# Jacobian for homogenous gas reactor\n",
    "\n",
    "***Energy equation***\n",
    "$$\n",
    "\\frac{dT}{dt}= -\\frac{1}{\\rho c_p}\\sum_{k=1}^{N_{spec}}\\dot{\\omega_{k}} W_k h_k = S_T\n",
    "$$\n",
    "\n",
    "***Species equation***\n",
    "$$\n",
    "\\frac{dY_k}{dt}=\\frac{1}{\\rho}\\dot{\\omega_{k}}W_k=S_{Y_k},\\,\\,\\,k=1\\ldots N_{spec}\n",
    "$$\n",
    "\n",
    "## Environment Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "TChem_install_directory ='where/tchem/is/installed'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.append(TChem_install_directory+'/lib')\n",
    "import pytchem\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "sys.path.append(TChem_install_directory+'/example/runs/scripts/')\n",
    "import pmixSample"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pre-simulation\n",
    "* Set variables; temperature and stoichiometric ratio (fuel/air).\n",
    "* Convert from stoichiometric ratio to mass fraction of CH4, O2, N2 and AR.\n",
    "* Create samples spaning over the variable ranges."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Pressure, Temperature, phi(stoichiometric ratio)\n",
    "one_atm = 101325 # [Pa]\n",
    "TempMax = 1300   # Maximum temperature [K]\n",
    "TempMin = 1000   # Minimum temperature [K]\n",
    "\n",
    "PressureMax = 1*one_atm; # [Pa]\n",
    "PressureMin = 1*one_atm; # [Pa]\n",
    "\n",
    "phiMax = 3.0; # Maximum equivalence ratio [-]\n",
    "phiMin = 0.8; # Minimum equivalence ratio [-]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "Npp = 1\n",
    "Npt = 2 \n",
    "Npphi = 2\n",
    "N = Npp*Npt*Npphi\n",
    "\n",
    "pressure    = [PressureMin] #\n",
    "temperature = np.linspace(TempMin, TempMax, Npt)\n",
    "eqratio     = np.linspace(phiMin, phiMax, Npphi)\n",
    "p, temp, phi = np.meshgrid(pressure, temperature,eqratio)\n",
    "p    = p.reshape(np.size(p))       #flatten()\n",
    "temp = temp.reshape(np.size(temp)) #flatten()\n",
    "phi  = phi.reshape(np.size(phi))   #flatten()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "Nvar = 6\n",
    "sample = np.zeros([N,Nvar])\n",
    "fuel =\"CH4\"\n",
    "nC=1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i in range(N):\n",
    "    sample[i,0] = temp[i]\n",
    "    sample[i,1] = p[i]\n",
    "    Yp_fuel, Yr_o2, Yr_n2, Yr_ar = pmixSample.getMassFraction(nC,phi[i])\n",
    "    sample[i,2] = Yp_fuel\n",
    "    sample[i,3] = Yr_o2\n",
    "    sample[i,4] = Yr_n2 \n",
    "    sample[i,5] = Yr_ar"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## TChem Simulation\n",
    "\n",
    "### Initialize TChem Driver Object\n",
    "\n",
    "* Initialization of Kokkos.\n",
    "* Create a TChem driver object. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "pytchem.initialize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "tchem = pytchem.TChemDriver()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Get help from TChem driver object."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on TChemDriver in module pytchem object:\n",
      "\n",
      "class TChemDriver(pybind11_builtins.pybind11_object)\n",
      " |  A class to manage data movement between numpy to kokkos views in TChem::Driver object\n",
      " |  \n",
      " |  Method resolution order:\n",
      " |      TChemDriver\n",
      " |      pybind11_builtins.pybind11_object\n",
      " |      builtins.object\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __init__(...)\n",
      " |      __init__(self: pytchem.TChemDriver) -> None\n",
      " |  \n",
      " |  cloneGasKineticModel(...)\n",
      " |      cloneGasKineticModel(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Internally create clones of the kinetic model\n",
      " |  \n",
      " |  computeGasEnthapyMass(...)\n",
      " |      computeGasEnthapyMass(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Compute enthalpy mass and mixture enthalpy\n",
      " |  \n",
      " |  computeGasNetProductionRatePerMass(...)\n",
      " |      computeGasNetProductionRatePerMass(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Compute net production rate\n",
      " |  \n",
      " |  computeGasReactionRateConstants(...)\n",
      " |      computeGasReactionRateConstants(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Compute forward/reverse rate constant\n",
      " |  \n",
      " |  computeJacobianHomogeneousGasReactor(...)\n",
      " |      computeJacobianHomogeneousGasReactor(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Compute Jacobian matrix for homogeneous gas reactor\n",
      " |  \n",
      " |  computeRHS_HomogeneousGasReactor(...)\n",
      " |      computeRHS_HomogeneousGasReactor(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Compute RHS for homogeneous gas reactor\n",
      " |  \n",
      " |  computeTimeAdvanceHomogeneousGasReactor(...)\n",
      " |      computeTimeAdvanceHomogeneousGasReactor(self: pytchem.TChemDriver) -> float\n",
      " |      \n",
      " |      Compute Time Advance for a Homogeneous-Gas Reactor\n",
      " |  \n",
      " |  createAllViews(...)\n",
      " |      createAllViews(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate all necessary workspace for this driver\n",
      " |  \n",
      " |  createGasEnthapyMass(...)\n",
      " |      createGasEnthapyMass(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for enthalpy mass  (# samples, # species )\n",
      " |  \n",
      " |  createGasKineticModel(...)\n",
      " |      createGasKineticModel(self: pytchem.TChemDriver, chemkin_input: str, thermo_data: str) -> None\n",
      " |      \n",
      " |      Create a kinetic model from CHEMKIN input files\n",
      " |  \n",
      " |  createGasKineticModelConstData(...)\n",
      " |      createGasKineticModelConstData(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Internally construct const object of the kinetic model and load them to device\n",
      " |  \n",
      " |  createGasKineticModelConstDataWithArreniusForwardParameters(...)\n",
      " |      createGasKineticModelConstDataWithArreniusForwardParameters(self: pytchem.TChemDriver, reac_indices: numpy.ndarray[numpy.int32], factors: numpy.ndarray[numpy.float64]) -> None\n",
      " |      \n",
      " |      Creates clones of the kinetic model; modifies the Arrhenius forward parameters of the clones;and creates a const object of the kinetics models.factors is a 3d array of size: number of samples, number of reactions to be modified, and 3 kinetic parameters. kinetic parameters: pre exponential (0), temperature coefficient(1), and activation energy(2)\n",
      " |  \n",
      " |  createGasNetProductionRatePerMass(...)\n",
      " |      createGasNetProductionRatePerMass(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for net production rate per mass (# samples, # species)\n",
      " |  \n",
      " |  createGasReactionRateConstants(...)\n",
      " |      createGasReactionRateConstants(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for forward/reverse rate constants  (# samples, # reactions )\n",
      " |  \n",
      " |  createJacobianHomogeneousGasReactor(...)\n",
      " |      createJacobianHomogeneousGasReactor(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for homogeneous-gas-reactor Jacobian  (# samples, # species + 1  # species + 1)\n",
      " |  \n",
      " |  createRHS_HomogeneousGasReactor(...)\n",
      " |      createRHS_HomogeneousGasReactor(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for homogeneous-gas-reactor RHS  (# samples, # species + 1 )\n",
      " |  \n",
      " |  createStateVector(...)\n",
      " |      createStateVector(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Allocate memory for state vector (# samples, state vector length)\n",
      " |  \n",
      " |  freeAllViews(...)\n",
      " |      freeAllViews(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Free all necessary workspace for this driver\n",
      " |  \n",
      " |  getGasArrheniusForwardParameter(...)\n",
      " |      getGasArrheniusForwardParameter(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getGasArrheniusForwardParameter(self: pytchem.TChemDriver, reac_indices: numpy.ndarray[numpy.int32], param_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive pre exponential for reactions listed by reaction_indices\n",
      " |      \n",
      " |      2. getGasArrheniusForwardParameter(self: pytchem.TChemDriver, imodel: int, reac_indices: numpy.ndarray[numpy.int32], param_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive pre exponential for reactions listed by reaction_indices\n",
      " |  \n",
      " |  getGasEnthapyMass(...)\n",
      " |      getGasEnthapyMass(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive enthalpy mass per species for all samples\n",
      " |  \n",
      " |  getGasEnthapyMixMass(...)\n",
      " |      getGasEnthapyMixMass(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve mixture enthalpy for all samples\n",
      " |  \n",
      " |  getGasForwardReactionRateConstants(...)\n",
      " |      getGasForwardReactionRateConstants(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getGasForwardReactionRateConstants(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive forward rate constants for a single sample\n",
      " |      \n",
      " |      2. getGasForwardReactionRateConstants(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve forward rate constants  for all samples\n",
      " |  \n",
      " |  getGasNetProductionRatePerMass(...)\n",
      " |      getGasNetProductionRatePerMass(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getGasNetProductionRatePerMass(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive net production rate for a single sample\n",
      " |      \n",
      " |      2. getGasNetProductionRatePerMass(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve net production rate for all samples\n",
      " |  \n",
      " |  getGasReverseReactionRateConstants(...)\n",
      " |      getGasReverseReactionRateConstants(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getGasReverseReactionRateConstants(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive reverse rate constants for a single sample\n",
      " |      \n",
      " |      2. getGasReverseReactionRateConstants(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve reverse rate constants  for all samples\n",
      " |  \n",
      " |  getJacobianHomogeneousGasReactor(...)\n",
      " |      getJacobianHomogeneousGasReactor(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive homogeneous-gas-reactor Jacobian for a single sample\n",
      " |  \n",
      " |  getLengthOfStateVector(...)\n",
      " |      getLengthOfStateVector(self: pytchem.TChemDriver) -> int\n",
      " |      \n",
      " |      Get the size of state vector i.e., rho, P, T, Y_{0-Nspec-1}\n",
      " |  \n",
      " |  getNumberOfReactions(...)\n",
      " |      getNumberOfReactions(self: pytchem.TChemDriver) -> int\n",
      " |      \n",
      " |      Get the number of reactions registered in the kinetic model\n",
      " |  \n",
      " |  getNumberOfSamples(...)\n",
      " |      getNumberOfSamples(self: pytchem.TChemDriver) -> int\n",
      " |      \n",
      " |      Get the number of samples which is currently used in the driver\n",
      " |  \n",
      " |  getNumberOfSpecies(...)\n",
      " |      getNumberOfSpecies(self: pytchem.TChemDriver) -> int\n",
      " |      \n",
      " |      Get the number of species registered in the kinetic model\n",
      " |  \n",
      " |  getRHS_HomogeneousGasReactor(...)\n",
      " |      getRHS_HomogeneousGasReactor(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getRHS_HomogeneousGasReactor(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrive homogeneous-gas-reactor RHS for a single sample\n",
      " |      \n",
      " |      2. getRHS_HomogeneousGasReactor(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve homogeneous-gas-reactor RHS_ for all samples\n",
      " |  \n",
      " |  getSpeciesIndex(...)\n",
      " |      getSpeciesIndex(self: pytchem.TChemDriver, species_name: str) -> int\n",
      " |      \n",
      " |      Get species index\n",
      " |  \n",
      " |  getStateVariableIndex(...)\n",
      " |      getStateVariableIndex(self: pytchem.TChemDriver, var_name: str) -> int\n",
      " |      \n",
      " |      Get state variable index\n",
      " |  \n",
      " |  getStateVector(...)\n",
      " |      getStateVector(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. getStateVector(self: pytchem.TChemDriver, sample_index: int) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve state vector for a single sample\n",
      " |      \n",
      " |      2. getStateVector(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve state vector for all samples\n",
      " |  \n",
      " |  getTimeStep(...)\n",
      " |      getTimeStep(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve time line of all samples\n",
      " |  \n",
      " |  getTimeStepSize(...)\n",
      " |      getTimeStepSize(self: pytchem.TChemDriver) -> numpy.ndarray[numpy.float64]\n",
      " |      \n",
      " |      Retrieve time step sizes of all samples\n",
      " |  \n",
      " |  modifyGasArrheniusForwardParameters(...)\n",
      " |      modifyGasArrheniusForwardParameters(self: pytchem.TChemDriver, reac_indices: numpy.ndarray[numpy.int32], factors: numpy.ndarray[numpy.float64]) -> None\n",
      " |      \n",
      " |      Modify the cloned kinetic models Arrhenius parameters\n",
      " |  \n",
      " |  setNumberOfSamples(...)\n",
      " |      setNumberOfSamples(self: pytchem.TChemDriver, number_of_samples: int) -> None\n",
      " |      \n",
      " |      Set the number of samples; this is used for Kokkos view allocation\n",
      " |  \n",
      " |  setStateVector(...)\n",
      " |      setStateVector(*args, **kwargs)\n",
      " |      Overloaded function.\n",
      " |      \n",
      " |      1. setStateVector(self: pytchem.TChemDriver, sample_index: int, 1d_state_vector: numpy.ndarray[numpy.float64]) -> None\n",
      " |      \n",
      " |      Overwrite state vector for a single sample\n",
      " |      \n",
      " |      2. setStateVector(self: pytchem.TChemDriver, 2d_state_vector: numpy.ndarray[numpy.float64]) -> None\n",
      " |      \n",
      " |      Overwrite state vector for all samples\n",
      " |  \n",
      " |  setTimeAdvanceHomogeneousGasReactor(...)\n",
      " |      setTimeAdvanceHomogeneousGasReactor(self: pytchem.TChemDriver, tbeg: float, tend: float, dtmin: float, dtmax: float, jacobian_interval: int, max_num_newton_iterations: int, num_time_iterations_per_interval: int, atol_newton: float, rtol_newton: float, atol_time: float, rtol_time: float) -> None\n",
      " |      \n",
      " |      Set time advance object for homogeneous gas reactor\n",
      " |  \n",
      " |  showViewStatus(...)\n",
      " |      showViewStatus(self: pytchem.TChemDriver) -> None\n",
      " |      \n",
      " |      Print member variable view status\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods inherited from pybind11_builtins.pybind11_object:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from pybind11_builtins.pybind11_type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(tchem)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Create Kinetic Model \n",
    "\n",
    "* Inputs are the reactions mechanism files; in this case, we use the GRI3.0 gas reaction mechanism"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "inputs_directory = TChem_install_directory + '/example/data/ignition-zero-d/gri3.0/'\n",
    "tchem.createGasKineticModel(inputs_directory+'chem.inp',inputs_directory+'therm.dat')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* Set number of samples\n",
    "* Internally construct const object of the kinetic model and load them to device"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "tchem.setNumberOfSamples(N)\n",
    "tchem.createGasKineticModelConstData()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Set State Vector\n",
    "\n",
    "* Get index for variables. \n",
    "* Pass a numpy array to the TChem object to set the state vector. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "Variables = ['T','P','CH4','O2','N2','AR']\n",
    "indx=[]\n",
    "for var in Variables:\n",
    "    indx += [tchem.getStateVariableIndex(var)]\n",
    "\n",
    "state = np.zeros([N, tchem.getLengthOfStateVector()])\n",
    "for sp in range(N):\n",
    "    state[sp,indx] = sample[sp,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "tchem.createStateVector()\n",
    "tchem.setStateVector(state)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "tchem.computeJacobianHomogeneousGasReactor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "jacobian = tchem.getJacobianHomogeneousGasReactor(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(54, 54)\n",
      "[[-1.29675785e-03 -1.14169098e+01  1.62362331e+10 ... -3.65045856e+01\n",
      "  -2.48517813e+08 -7.47820624e+02]\n",
      " [ 0.00000000e+00 -1.42542785e-04  3.85230404e+05 ...  0.00000000e+00\n",
      "   0.00000000e+00  0.00000000e+00]\n",
      " [ 4.81140419e-12  7.12720953e-05 -4.48862740e+05 ...  3.33532729e-09\n",
      "   2.60203217e+03 -5.75883890e-12]\n",
      " ...\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00 ... -5.89280062e-03\n",
      "   0.00000000e+00  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00 ...  0.00000000e+00\n",
      "  -2.09116838e+05  0.00000000e+00]\n",
      " [ 0.00000000e+00  0.00000000e+00  0.00000000e+00 ...  0.00000000e+00\n",
      "   0.00000000e+00 -1.97077911e-01]]\n"
     ]
    }
   ],
   "source": [
    "print(np.shape(jacobian))\n",
    "print(jacobian)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "# compute rhs of Homogeneous Gas Reactor\n",
    "tchem.computeRHS_HomogeneousGasReactor()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([-4.75837752e-02,  0.00000000e+00,  9.70832134e-11,  6.78919068e-15,\n",
       "       -8.32264203e-06,  0.00000000e+00,  0.00000000e+00,  8.58480727e-06,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  3.91195170e-06, -4.17421403e-06,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  9.26413468e-16,\n",
       "        0.00000000e+00,  0.00000000e+00,  1.83880439e-14,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "       -1.25979150e-14,  0.00000000e+00,  0.00000000e+00,  0.00000000e+00,\n",
       "        0.00000000e+00,  0.00000000e+00])"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# get RHS for sample 0\n",
    "tchem.getRHS_HomogeneousGasReactor(0)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finalize Kokkos. This deletes the TChem object and the data stored as Kokkos views"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "del(tchem)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "pytchem.finalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
